#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import webbrowser
import time
import subprocess
import sys
import os

def check_backend():
    """检查后端是否正在运行"""
    try:
        import requests
        response = requests.get("http://localhost:8000", timeout=5)
        return response.status_code == 200
    except:
        return False

def start_frontend():
    """启动前端页面"""
    try:
        # 检查后端是否正在运行
        if not check_backend():
            print("警告: 后端服务似乎未运行")
            print("请先启动后端服务: python start_backend.py")
            print("")
        
        # 打开前端页面
        frontend_url = "http://localhost:8000/static/index.html"
        print(f"正在打开前端页面: {frontend_url}")
        webbrowser.open(frontend_url)
        
        print("前端页面已在浏览器中打开")
        print("如果页面未正确显示，请确保后端服务正在运行")
        
    except Exception as e:
        print(f"打开前端页面时出错: {e}")

def main():
    """主函数"""
    print("网络云运维日报故障处理上报系统 - 前端页面")
    print("=" * 40)
    print("")
    
    # 启动前端页面
    start_frontend()
    
    print("")
    print("按 Ctrl+C 退出...")
    try:
        while True:
            time.sleep(1)
    except KeyboardInterrupt:
        print("\n前端页面已关闭")
        sys.exit(0)

if __name__ == "__main__":
    main()